package top.bluesword.laboratory.util;

/**
 * @author 李林峰
 */
public class PostgresqlRegexUtils {

    private static final String REGEX_ESCAPE_CHAR = "\\\\";

    private static final String[] KEYWORDS = {"$", "(", ")", "*", "+", ".", "[", "]", "?", "^", "{", "}", "|"};

    public static String escapeRegex(String str) {
        if (str == null) {
            return null;
        }
        str = str.replace("\\","\\\\\\\\");
        for (String keyword : KEYWORDS) {
            str = str.replace(keyword, REGEX_ESCAPE_CHAR + keyword);
        }
        return str;
    }
}
